<template>
  <div>
    <van-nav-bar
        title="服务详情"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
    />
    <!--    {{ standardOne }}-->
    <h2 style="text-align: center">{{ standardOne.mdname }}</h2>
    <van-card
        :title="standardOne.xiche"
        thumb="https://hh666.oss-cn-beijing.aliyuncs.com/ffb5bb8fa0fffa31a5a9fb05a0beaffb.jpeg"
        :price="standardOne.jiage"
        :origin-price="standardOne.menshi"
    >
      <template #tags>
        <van-tag plain type="primary">未消费，随时退</van-tag>
        <van-tag plain type="primary">过期退</van-tag>
      </template>
    </van-card>
    <div class="qianggoou2">
      <van-cell-group>
        <van-card>
          <template #tags>
            <span class="jiage"><span>当前价格:</span> <span class="daxiao">{{ standardOne.jiage }}</span></span>
            <span class="zhekou"><span>折扣前:</span><span class="daxiao1"><s>{{ standardOne.menshi }}</s></span></span>
            <span class="ti"><van-button class="tijiao" @click="tijiao()">提交订单</van-button></span>
          </template>
        </van-card>
      </van-cell-group>
    </div>
  </div>
</template>
<script>
import {findUserById} from "@/api/wode/user";

const coupon = {
};
export default {
  data() {
    return {
      showList: false,
      id: 0,
      chosenCoupon: -1,
      coupons: [coupon],
      disabledCoupons: [coupon],
      standardOne: {},
      orderInfo: {},
      user: {}
    }
  },
  methods: {
    findUserById() {
      findUserById(localStorage.getItem('token')).then(res => {
        if (res.code == 208) {
          this.$message.error(res.message)
          localStorage.removeItem('token')
          this.$router.push('/')
        }
        this.user = res.data

      }).catch(error => {
        console.log(error)
      })
    },
    tijiao() {
      this.orderInfo.ordermdname = this.standardOne.mdname
      this.orderInfo.price = this.standardOne.menshi
      this.orderInfo.userId = this.user.id
      this.orderInfo.discount = Number(this.standardOne.menshi) - Number(this.standardOne.jiage)
      this.orderInfo.photo = "https://hh666.oss-cn-beijing.aliyuncs.com/ffb5bb8fa0fffa31a5a9fb05a0beaffb.jpeg"
      this.$router.push({path: '/Wxprice', query: this.orderInfo})
      this.$router.push({path: '/Wxprice', query: {id: this.id}})
    },
    onChange(index) {
      this.showList = false;
      this.chosenCoupon = index;
    },
    onExchange(code) {
      this.coupons.push(coupon);
    },
    findStandardOne() {
      this.axios.get(`http://1.94.221.254:9999/api-qcfw-mendian/home/standard/findStandardOne/${this.id}`).then(res => {
        this.standardOne = res.data.data
        console.log(res.data.data)
        console.log(this.standardOne)
      })
    },
    onClickLeft() {
      this.$router.push('/qingxi')
    }
  },
  created() {
    this.id = this.$route.query.id
    console.log(this.id)
    this.findStandardOne()
    this.findUserById()

    var token = localStorage.getItem('token');
    if (token === null) {
      this.$router.push('/');
    }
  }
}
</script>
<style scoped>
.qianggoou2 {
  height: 30px;
  margin-top: 120%;
}

.jiage {
  padding-left: 10px;
  padding-top: 70px;
  float: left;

}

.zhekou {
  margin-left: 10px;
  padding-top: 70px;
}

.ti {
  padding-top: 60px;
  float: right;
}

.tijiao {
  border-radius: 30px;
  width: 130px;
  background-color: #FB4D03;
  color: white;
}

.daxiao {
  font-size: 22px;
  color: red;
}

.daxiao1 {
  font-size: 15px;
  color: #c61b1b;
}
</style>
